package com.achobeta.recruitment.message;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-10-19
 * Time: 0:37
 */

@Data
@XStreamAlias("xml")
public class TextMessage {
    @XStreamAlias("ToUserName")
    private String toUserName;

    @XStreamAlias("FromUserName")
    private String fromUserName;

    @XStreamAlias("CreateTime")
    private long createTime;

    @XStreamAlias("MsgType")
    private String msgType;

    @XStreamAlias("Content")
    private String content;

    /**
     * 将map转换为对象返回
     * @param map 基本消息
     * @return
     */
    public static TextMessage getReplyTextMessage(Map<String, Object> map) {
        TextMessage message = new TextMessage();
        message.setToUserName((String) map.get("FromUserName"));
        message.setFromUserName((String) map.get("ToUserName"));
        message.setCreateTime(System.currentTimeMillis() / 1000);
        message.setMsgType("text");
        message.setContent((String) map.get("Content"));
        return message;
    }
}
